package com.twang.stock.task;

import com.alibaba.fastjson.JSONObject;
import com.twang.stock.common.http.HtmlTools;
import com.twang.stock.design.impl.*;
import com.twang.stock.dto.EmailMessage;
import com.twang.stock.dto.IndexedInfo;
import com.twang.stock.dto.StockMinutesMessage;
import com.twang.stock.dto.TenXunStock;
import com.twang.stock.entity.*;
import com.twang.stock.entity.ex.HotTagStockInfo;
import com.twang.stock.entity.ex.TodayQinXuDto;
import com.twang.stock.mapper.*;
import com.twang.stock.redis.RedisUtil;
import com.twang.stock.rocketMq.RocketMQProducer;
import com.twang.stock.service.*;
import com.twang.stock.service.impl.TodayQinXuServiceImpl;
import com.twang.stock.service.jinyan.CommonService;
import com.twang.stock.email.SendmailService;
import com.twang.stock.task.old.BaseTask;
import com.twang.stock.utils.date.DateUtils;
import com.twang.stock.utils.date.HolidayCopy;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.assertj.core.util.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * 通知个股买点:http://127.0.0.1/utils/notifyStockBuyTask
 */

@Service
@Slf4j
public class NotifyStockBuyTask extends BaseTask {

    @Autowired
    private TodayQinXuService todayQinXuService;

    @Autowired
    private RedisUtil redisUtil;

    @Resource
    private HkShMoneyInOutMapper hkShMoneyInOutMapper;

    @Resource
    private ThsReDianStockMapper thsReDianStockMapper;

    @Autowired
    private IndexService indexService;

    @Resource
    private TodayQinXuMapper todayQinXuMapper;

    @Autowired
    private ZhangTingBanService zhangTingBanService;

    @Resource
    private HotTagMapper hotTagMapper;

    @Resource
    private WenCaiDataMapper wenCaiDataMapper;

    @Autowired
    private ZiXuanBanKuaiTask ziXuanBanKuaiTask;

    @Resource
    private CompanyStockMinutesMapper companyStockMinutesMapper;

    @Autowired
    private TodayTrade50AmountTask todayTrade50AmountTask;

    @Autowired
    private CompanyStockMinutesService companyStockMinutesService;

    @Autowired
    private CommonService commonService;
    @Resource
    private UserMapper userMapper;
    @Resource
    private CompanyStockMapper companyStockMapper;

    @Autowired
    private RocketMQProducer rocketMQProducer;

    @Autowired
    private NotifyStockBuyService notifyStockBuyService;


    @Resource
    private SendmailService sendmailService;

//    @Scheduled(cron = "0 0/1 * * * ?")
    public void execute() throws Exception {
        if (!isWorkTradeTime()) {
            return;
        }
        //触发做T
       // extracted();
        刷新数据();
        //

    }

    void extracted() {
        try {
             // 做T预警();
            StockMinutesMessage message = new StockMinutesMessage();
            message.setMinutes(HolidayCopy.getHHmmss().substring(8, 12));
            message.setDate(HolidayCopy.getRealToday());
            message.setType(StockMinutesMessage.TYPE_MINUTES_ZUO_T);
            log.info(">>>>>>>>>>>> covertDTO  message={}",JSONObject.toJSONString(message));
            rocketMQProducer.sendOneWay(JSONObject.toJSONString(message));
        }catch (Exception e){
            log.error(" 做T预警 触发失败 ");
            log.error("{}",e);
        }
    }

    public void 刷新数据() throws Exception {
        try {
            // 调用消费者消费，异步处理;
            StockMinutesMessage message = new StockMinutesMessage();
            message.setMinutes(HolidayCopy.getHHmmss().substring(8, 12));
            message.setDate(HolidayCopy.getRealToday());
            message.setType(StockMinutesMessage.TYPE_MINUTES_INDEX_INFO);
            log.info(">>>>>>>>>>>> covertDTO  message={}",JSONObject.toJSONString(message));
            rocketMQProducer.sendOneWay(JSONObject.toJSONString(message));
        }catch (Exception e){
            log.error(" 主页更新 触发失败 ");
            log.error("{}",e);
        }
//        北上资金();
//        今日大盘();
//        获取今日板块涨幅排行();
//        同花顺热度榜单1H();
//        同花顺热度榜单24H();
//        大盘涨跌情况();
//        判断情绪();
//        获取自制板块信息();
//        获取大盘数据();
//        年度涨幅前20();
    }

    public void 做T预警() {
        String key="";
        List<String> ids = Arrays.asList(commonService.getValue("warn_zuoT_ID").toString().split(","));
        for (String id : ids) {
            User user = userMapper.selectByPrimaryKey(Long.valueOf(id));
            CompanyStock companyStock = new CompanyStock();
            companyStock.setUserId(user.getId().intValue());
            List<CompanyStock> companyStockList=  companyStockMapper.select(companyStock);
            StringBuffer buffer = new StringBuffer("");
            if (null != user && CollectionUtils.isNotEmpty(companyStockList)) {
                //adminFuPan(user.getEmail());
                for (CompanyStock companyStock1 : companyStockList) {
                    buffer.append(companyStock1.getCompanyCode()).append(",");
                }
                key=buffer.toString().replace("s_s_","s_").replace(",s_,",",");
                判断是否触发预警(user,key);
            }
        }
    }

    private void 判断是否触发预警(User user,String key) {
        List<TenXunStock> tenXunStocks = HtmlTools.httpGet(key);
        tenXunStocks.stream().forEach(p -> {
            if (51 == p.getExchange()) {
                p.setStockCode("sz" + p.getStockCode());
            } else {
                p.setStockCode("sh" + p.getStockCode());
            }
            List<String> dates = companyStockMinutesMapper.queryDates();
            /** 昨天 */
            int i = 2;
            int j = 0;
            BigDecimal hisDayTradeVol = BigDecimal.ZERO;
            for (String date : dates) {
                date = dates.get(dates.size() - i);
                //排除涨停的数据
                Boolean isTrue = zhangTingBanService.zhangtingDatahis(p.getStockCode(), date);
                if (!isTrue) {
                    BigDecimal yestoDayMaxVol = companyStockMinutesService.getMaxVol(date, p.getStockCode());
                    hisDayTradeVol = hisDayTradeVol.add(yestoDayMaxVol);
                    j++;
                }
                i++;
                if (j == 4) {
                    break;
                }
            }
            if(p.getStockCode().startsWith("sh688")){
                hisDayTradeVol=hisDayTradeVol.divide(new BigDecimal(100)).setScale(0,BigDecimal.ROUND_HALF_UP);
            }
            //更新分钟量能
            Example example = new Example(CompanyStockMinutes.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andEqualTo("date", HolidayCopy.getRealToday());
            criteria.andEqualTo("companyCode", p.getStockCode());
            example.orderBy("id").desc();
            List<CompanyStockMinutes> list = companyStockMinutesMapper.selectByExample(example);
            if (org.apache.commons.collections.CollectionUtils.isNotEmpty(list)) {
                CompanyStockMinutes last = list.get(0);
                BigDecimal newVole = p.getTradingVolume().subtract(last.getTradeVol());
                if (newVole.compareTo(hisDayTradeVol) > 0) {
                    //触发了
                    p.setTFlags(1);
                    sendEmail(user.getEmail(),p);
                } else {
                    p.setTFlags(0);
                }
//                sendEmail(user.getEmail(),p);
            }
            p.setTurnover(p.getTradingVolume().divide(new BigDecimal(10000)).setScale(2, BigDecimal.ROUND_HALF_UP));
        });
    }

    public void sendEmail(String email, TenXunStock p) {
        if(null!=email) {
            log.info(">>>>>>>>> send email={}",email);
            String messages = new StringBuffer("触发做T时间：").append(DateUtils.getNow()).toString();
            try{
                EmailMessage emailMessage=new EmailMessage();
                emailMessage.setCode(p.getStockCode());
                emailMessage.setName(p.getStockName());
                emailMessage.setEmail(email.toString());
                emailMessage.setMessage(messages);
                //emailMessage.setUserId();
                //String reg="|";
                //String msg=  new StringBuffer(messages).append(reg).append(p.getStockName()).append(reg).append(p.getStockCode()).append(reg).append(email).toString();
                // rocketMQProducer.sendOneWay(JSONObject.toJSONString(emailMessage));
                rocketMQProducer.sendOneWay(JSONObject.toJSONString(emailMessage));
            }catch (Exception e){
                sendmailService.sendMailWithByZuoT(messages, p.getStockName(), p.getStockCode(), email.toString());
            }
        }
    }

    public void 获取自制板块信息() {
        List<HotTagStockInfo> ai_hx = hotTagMapper.queryListByType(ZiXuanBanKuaiTask.TYPE_ZX_TAG_AI_HX);
        Boolean ai_hx_flag = ziXuanBanKuaiTask.setZhangDie(ai_hx);
        redisUtil.set(ZiXuanBanKuaiTask.cache_key_ai_hx, JSONObject.toJSONString(ai_hx));
        redisUtil.set(ZiXuanBanKuaiTask.cache_key_ai_hx_flag, ai_hx_flag);


        List<HotTagStockInfo> ai_qxlt = hotTagMapper.queryListByType(ZiXuanBanKuaiTask.TYPE_ZX_TAG_AI_QXLT);
        Boolean ai_qxlt_flag = ziXuanBanKuaiTask.setZhangDie(ai_qxlt);
        redisUtil.set(ZiXuanBanKuaiTask.cache_key_ai_qxlt, JSONObject.toJSONString(ai_qxlt));
        redisUtil.set(ZiXuanBanKuaiTask.cache_key_ai_qxlt_flag, ai_qxlt_flag);


        List<HotTagStockInfo> ztg_hx = hotTagMapper.queryListByType(ZiXuanBanKuaiTask.TYPE_ZX_TAG_ZTG_HX);
        Boolean ztg_hx_flag = ziXuanBanKuaiTask.setZhangDie(ztg_hx);
        redisUtil.set(ZiXuanBanKuaiTask.cache_key_ztg_hx, JSONObject.toJSONString(ztg_hx));
        redisUtil.set(ZiXuanBanKuaiTask.cache_key_ztg_hx_flag, ztg_hx_flag);


        List<HotTagStockInfo> ztg_qxlt = hotTagMapper.queryListByType(ZiXuanBanKuaiTask.TYPE_ZX_TAG_ZTG_QXLT);
        Boolean ztg_qxlt_flag = ziXuanBanKuaiTask.setZhangDie(ztg_qxlt);
        redisUtil.set(ZiXuanBanKuaiTask.cache_key_ztg_qxlt, JSONObject.toJSONString(ztg_qxlt));
        redisUtil.set(ZiXuanBanKuaiTask.cache_key_ztg_ztg_qxlt_flag, ztg_qxlt_flag);


        List<HotTagStockInfo> yao_gu = hotTagMapper.queryListByType(ZiXuanBanKuaiTask.TYPE_ZX_TAG_YAO_GU);
        Boolean yao_gu_flag = ziXuanBanKuaiTask.setZhangDie(yao_gu);
        redisUtil.set(ZiXuanBanKuaiTask.cache_key_yao_gu, JSONObject.toJSONString(yao_gu));
        redisUtil.set(ZiXuanBanKuaiTask.cache_key_yao_gu_flag, yao_gu_flag);
    }

    public void 判断情绪() throws Exception {
        List<String> days=todayQinXuMapper.queryDates();
        List<String> tradeDays= Lists.newArrayList();
        List<BigDecimal> szTradeAmount= Lists.newArrayList();
        List<BigDecimal> shTradeAmount= Lists.newArrayList();
        List<BigDecimal> totalTradeAmount= Lists.newArrayList();

        for(int i=30;i>=0;i--) {
            TodayQinXu todayQinXu = todayQinXuService.queryByDayLastOne(days.get(i));
            if(null==todayQinXu.getTotalAmount()){
                continue;
            }
            tradeDays.add(days.get(i));
            szTradeAmount.add(todayQinXu.getSzTradeSum().divide(new BigDecimal(100000000)).setScale(2, BigDecimal.ROUND_HALF_UP));
            shTradeAmount.add(todayQinXu.getShTradeSum().divide(new BigDecimal(100000000)).setScale(2, BigDecimal.ROUND_HALF_UP));
            totalTradeAmount.add(todayQinXu.getTotalAmount().divide(new BigDecimal(100000000)).setScale(2, BigDecimal.ROUND_HALF_UP));

            if (i == 0) {
                todayQinXu.setShTradeSum(todayQinXu.getShTradeSum().divide(new BigDecimal(100000000)).setScale(2, BigDecimal.ROUND_HALF_UP));
                todayQinXu.setSzTradeSum(todayQinXu.getSzTradeSum().divide(new BigDecimal(100000000)).setScale(2, BigDecimal.ROUND_HALF_UP));
                List<TodayQinXu> todayQinXuList = todayQinXuService.queryByDate(todayQinXu.getDate());
                List<TodayQinXu> min1000 = todayQinXuList.stream().filter(p -> p.getMinutes().equals("1000")).collect(Collectors.toList());
                BigDecimal qinxuSum = BigDecimal.ZERO;
                if (CollectionUtils.isEmpty(min1000)) {
                    List<TodayQinXu> min0959 = todayQinXuList.stream().filter(p -> p.getMinutes().equals("0959")).collect(Collectors.toList());
                    if (CollectionUtils.isEmpty(min0959)) {
                        List<TodayQinXu> min0958 = todayQinXuList.stream().filter(p -> p.getMinutes().equals("0958")).collect(Collectors.toList());
                        if (CollectionUtils.isNotEmpty(min0958)) {
                            qinxuSum = min0958.get(0).getShTradeSum().divide(new BigDecimal(100000000)).setScale(2, BigDecimal.ROUND_HALF_UP);
                        } else {
                            List<TodayQinXu> min1001 = todayQinXuList.stream().filter(p -> p.getMinutes().equals("1001")).collect(Collectors.toList());
                            if (CollectionUtils.isNotEmpty(min1001)) {
                                qinxuSum = min1001.get(0).getShTradeSum().divide(new BigDecimal(100000000)).setScale(2, BigDecimal.ROUND_HALF_UP);
                            }
                        }
                    } else {
                        qinxuSum = min0959.get(0).getShTradeSum().divide(new BigDecimal(100000000)).setScale(2, BigDecimal.ROUND_HALF_UP);
                    }
                } else {
                    qinxuSum = min1000.get(0).getShTradeSum().divide(new BigDecimal(100000000)).setScale(2, BigDecimal.ROUND_HALF_UP);
                }
                计算今日总风向(qinxuSum);
            }
            redisUtil.set(SumTotalTradeAmountTask.cache_key_szAndShTotalTradeSum, JSONObject.toJSONString(todayQinXu));
        }
        redisUtil.set(SumTotalTradeAmountTask.cache_key_tradeDays, JSONObject.toJSONString(tradeDays));
        redisUtil.set(SumTotalTradeAmountTask.cache_key_shTradeAmount, JSONObject.toJSONString(shTradeAmount));
        redisUtil.set(SumTotalTradeAmountTask.cache_key_szTradeAmount, JSONObject.toJSONString(szTradeAmount));
        redisUtil.set(SumTotalTradeAmountTask.cache_key_totalTradeAmount, JSONObject.toJSONString(totalTradeAmount));


        //涨停版
        {
            ZhangTingBan zhangTingBanParam = new ZhangTingBan();
            zhangTingBanParam.setDate(HolidayCopy.getRealToday());
            zhangTingBanParam.setLbc(new BigDecimal(11));
            List<ZhangTingBan> list = zhangTingBanService.list(zhangTingBanParam, null);
            List<ZhangTingBan> zhangTingBanList=Lists.newArrayList();
            for(int i=0;i<=6;i++){
                ZhangTingBan zhangTingBan = list.get(i);
                String code=zhangTingBan.getCode();
                if (code.startsWith("6")) {
                    code = "sh" + code;
                } else {
                    code = "sz" + code;
                }
                zhangTingBan.setCode(code);
                zhangTingBanList.add(zhangTingBan);
            }
            redisUtil.set(SumTotalTradeAmountTask.cache_key_zhangTingBanList, JSONObject.toJSONString(zhangTingBanList));
        }
    }

    public void 计算今日总风向(BigDecimal qinxuSum) {
        String LNQX="";
        //量能情绪，10点之后
        {
            if(!DateUtils.JudgeTime("09:30:00", "10:00:00")) {
                if (qinxuSum.compareTo(new BigDecimal(1200)) == 1) {
                    //<1200
                    LNQX=SumTotalTradeAmountTask.LNQX_1;
                } else {
                    //1000<<1200
                    if (qinxuSum.compareTo(new BigDecimal(1000)) == 1) {
                        LNQX=SumTotalTradeAmountTask.LNQX_2;
                    } else  {
                        //<900
                        LNQX=SumTotalTradeAmountTask.LNQX_3;
                    }
                }
            }else{
                LNQX="計算中...";
            }
        }
        redisUtil.set(SumTotalTradeAmountTask.cache_key_LNQX, LNQX);
    }

    public void 大盘涨跌情况() throws Exception {
        TodayQinXu param = new TodayQinXu();
        param.setDate(HolidayCopy.getRealToday());
        List<TodayQinXu> result = todayQinXuService.queryList(param, TodayQinXuServiceImpl.TYPE_SHORT_ASC);
        redisUtil.set(ZhangDieTingTask.cache_key, JSONObject.toJSONString(result));
    }

    public void 同花顺热度榜单1H() throws Exception {
        List<ThsReDianStock> list = thsReDianStockMapper.selectOneHourData();
        List<ThsHotStock> onethsHotStockList = Lists.newArrayList();
        indexService.getThsHotStockList(list, onethsHotStockList, OneThsHotStockListTask.dataSize);
        redisUtil.set(OneThsHotStockListTask.cache_key, JSONObject.toJSONString(onethsHotStockList), IndexedInfo.CACHE_TIME_10);
    }
    public void 同花顺热度榜单24H() throws Exception {
        List<ThsReDianStock> list = thsReDianStockMapper.select24HourData();
        List<ThsHotStock> thsHotStockList = Lists.newArrayList();
        indexService.getThsHotStockList(list, thsHotStockList, ThsHotStockListTask.dataSize);
        redisUtil.set(ThsHotStockListTask.cache_key, JSONObject.toJSONString(thsHotStockList), IndexedInfo.CACHE_TIME_10);
    }

    public void 获取大盘数据() {
        List<DfcfZhangDie> dfcfZhangDies = QueryBanKuaiAndDaPan.getDfcfZhangDie();
        redisUtil.set(DfcfZhangDieModel.cache_key, JSONObject.toJSONString(dfcfZhangDies));
        {
            BigDecimal AtotalAmount = dfcfZhangDies.stream().map(detail -> Optional.ofNullable(detail.getSzcje()).orElse(BigDecimal.ZERO)).reduce(BigDecimal.ZERO, BigDecimal::add).divide(new BigDecimal(100000000)).setScale(2, BigDecimal.ROUND_HALF_UP);
            //量能情绪（总体量能），10点之后
            Boolean 预警短线高度板块分线提示 = Boolean.FALSE;
            String LNQX = "";
            {
                //早盘1小时，过3000亿，甚至4000亿。
                if (DateUtils.JudgeTime("09:30:00", "10:00:00")) {
                    if (AtotalAmount.compareTo(new BigDecimal(3000)) == 1) {
                        //过3000亿
                        LNQX = SumTotalTradeAmountTask.LNQX_4;
                    }
                    预警短线高度板块分线提示 = Boolean.TRUE;
                }
                if (DateUtils.JudgeTime("09:30:00", "11:30:00")) {
                    if (AtotalAmount.compareTo(new BigDecimal(6000)) == 1) {
                        //过6000亿
                        LNQX = SumTotalTradeAmountTask.LNQX_4;
                    }
                    预警短线高度板块分线提示 = Boolean.TRUE;
                }
                if (AtotalAmount.compareTo(new BigDecimal(10000)) == 1) {
                    //过6000亿
                    LNQX = SumTotalTradeAmountTask.LNQX_4;
                }
                预警短线高度板块分线提示 = Boolean.TRUE;
                if(StringUtils.isNotBlank(LNQX)){
                    redisUtil.set(SumTotalTradeAmountTask.cache_key_LNQX, LNQX);
                }
            }
            //提示风险预警，短线高度板块可能下午就要开始跳水，别再上小市值高度票，这时候要关注大票


        }
    }

    public void 获取今日板块涨幅排行() throws Exception {
        //查询
        List<DfcfBnakKuai> dfcfBnakKuais = QueryBanKuaiAndDaPan.geBKZF("");
        redisUtil.set(DfcfBnakKuaisTask.cache_key, JSONObject.toJSONString(dfcfBnakKuais));
    }

    public void 今日大盘() {
        TodayQinXuDto todayQinXu = QueryBanKuaiAndDaPan.getTodayQinXu();
        redisUtil.set(TodayQinXuTask.cache_key, JSONObject.toJSONString(todayQinXu));
        //量能
        List<String> days = todayQinXuMapper.queryDates();
        List<TodayQinXuDto> todayQinXuDtos = todayQinXuMapper.queryTodayAndYesTodayAmount(days.get(0), days.get(1));

        //分钟
        List<String> minutes = todayQinXuDtos.stream().map(TodayQinXuDto::getMinutes).collect(Collectors.toList());
        redisUtil.set(TodayQinXuTask.cache_key_minutes, JSONObject.toJSONString(minutes));

        //今日
        List<BigDecimal> todayAmounts = todayQinXuDtos.stream().map(TodayQinXuDto::getTodayTradeAmount).collect(Collectors.toList());
        redisUtil.set(TodayQinXuTask.cache_key_toDay, JSONObject.toJSONString(todayAmounts));

        //昨日
        List<BigDecimal> yesTodayAmounts = todayQinXuDtos.stream().map(TodayQinXuDto::getYesTodayTradeAmount).collect(Collectors.toList());
        redisUtil.set(TodayQinXuTask.cache_key_yesToday, JSONObject.toJSONString(yesTodayAmounts));

    }

    /**
     * 北上资金
     * @throws Exception
     */
    public void 北上资金() throws Exception {
        HkShMoneyInOut hkShMoneyInOut = QueryBanKuaiAndDaPan.getHGTInOut();
        redisUtil.set(DfcfBeiShangZiJingTask.cache_key, JSONObject.toJSONString(hkShMoneyInOut));
        hkShMoneyInOutMapper.insert(hkShMoneyInOut);
    }

    /**
     * 年度涨幅
     * @throws Exception
     */
    public void 年度涨幅前20() {
        List<WenCaiData> wenCaiDataList = wenCaiDataMapper.selectAll();
        if(CollectionUtils.isNotEmpty(wenCaiDataList)){
            wenCaiDataList.forEach(item->{
                setZhangDie(item);
            });
        }

        {
            //更新今日情绪涨停前20指数信息
            TodayQinXu todayQinXu = todayQinXuMapper.queryByDayLastOneWhithNoparam();
            BigDecimal 前20累计涨幅 = (wenCaiDataList.stream().map(detail -> new BigDecimal(detail.getLatestChange())).reduce(BigDecimal.ZERO, BigDecimal::add));
            todayQinXu.setZhangFuBangZhiShu(前20累计涨幅);
            BigDecimal 前20累计成交量 = (wenCaiDataList.stream().map(detail -> Optional.ofNullable(detail.getTradelVol()).orElse(BigDecimal.ZERO)).reduce(BigDecimal.ZERO, BigDecimal::add));
            todayQinXu.setZhangFuBangChengJiaoLiangVol(前20累计成交量);
            BigDecimal 前20累计成交额 = (wenCaiDataList.stream().map(detail -> Optional.ofNullable(detail.getTradelAmount()).orElse(BigDecimal.ZERO)).reduce(BigDecimal.ZERO, BigDecimal::add));
            todayQinXu.setZhangFuBangChengJiaoLiangAmount(前20累计成交额);

            //成交额前20
            List<CompanyStockMinutes> cheList = todayTrade50AmountTask.getTradeAmountDESC(null, companyStockMinutesMapper.queryYesterDayNew()).subList(0,20);
            BigDecimal 成交额前20累计涨幅 = (cheList.stream().map(detail ->Optional.ofNullable(detail.getZhangDie()).orElse(BigDecimal.ZERO)).reduce(BigDecimal.ZERO, BigDecimal::add));
            todayQinXu.setCjeZhiShu(成交额前20累计涨幅);
            BigDecimal 成交额前20累计成交量 = (cheList.stream().map(detail -> Optional.ofNullable(detail.getTradeVol()).orElse(BigDecimal.ZERO)).reduce(BigDecimal.ZERO, BigDecimal::add));
            todayQinXu.setCjeVol(成交额前20累计成交量);
            BigDecimal 成交额前20累计成交额 = (cheList.stream().map(detail -> Optional.ofNullable(detail.getTradeSum()).orElse(BigDecimal.ZERO)).reduce(BigDecimal.ZERO, BigDecimal::add));
            todayQinXu.setCjeAmount(成交额前20累计成交额);

            //
            todayQinXuMapper.updateByPrimaryKey(todayQinXu);
            redisUtil.set(WenCaiDataTask.CACHE_KEY_TOP, JSONObject.toJSONString(todayQinXu));

        }

        redisUtil.set(WenCaiDataTask.cache_key, JSONObject.toJSONString(wenCaiDataList.subList(0,WenCaiDataTask.size)));
    }
    public void  setZhangDie(WenCaiData item){
            String[] str=item.getStockCode().split("\\.");
            String code=str[1].toLowerCase()+str[0];
            CompanyStockMinutes companyStockMinutes =companyStockMinutesMapper.queryByCode(code);
            if(null!=companyStockMinutes){
                item.setLatestChange(companyStockMinutes.getZhangDie().toString());
                item.setStockCode(code);
                item.setTradelAmount(companyStockMinutes.getTradeSum());
                item.setTradelVol(companyStockMinutes.getTradeVol());
                wenCaiDataMapper.updateByPrimaryKey(item);
            }else{
                item.setLatestChange("0");
            }
    }


}
